package com.star.enums;

import lombok.Getter;

/**
 * @Classname StateEnum
 * @Author Star
 * @Date 2021/4/25 - 20:49
 * @Description 通用状态码
 */
@Getter
public enum StateEnum {
    //店铺状态
    CHECK(1, "审核中"), OFFLINE(2, "非法店铺"), PASS(3, "通过认证"),
    //登录状态
    FROST(11, "冻结"), DELETED(12, "删除"), NORMAL(13, "正常"),
    //通用状态
    SUCCESS(0, "操作成功"),
    INNER_ERROR(-1001, "内部系统错误"),
    NULL_USERLOGIN(-1002, "userlogin登录信息信息为空"),
    NULL_SHOP(-1003, "shop店铺信息为空"),
    NULL_AREA(-1004, "location位置信息为空"),
    NULL_CATEGORY(-1006, " shopType店铺类型信息为空"),
    NULL_Role(-1007, " Role角色信息为空"),
    NULL_USERINFO(-1008, "userinfo用户信息为空"),
    INSERT_SUCCESS(201, "新增成功"),
    UPDATE_SUCCESS(202, "更新成功"),
    DELETE_SUCCESS(203, "删除成功"),
    UPLOAD_SUCCESS(204, "上传成功"),
    DOWNLOAD_SUCCESS(205, "下载成功"),
    LOGIN_SUCCESS(206, "登陆成功"),
    LOGIN_ADMIN(999, "管理员登录"),
    LOGOUT_SUCCESS(207, "登出成功"),
    LOGIN_ERROR(208, "登陆错误"),
    LOGIN_EXPIRE(209, "登陆过期"),
    RES_SUCCESS(400, "注册成功"),
    RES_ERROR(401, "用户名已存在"),
    ACCESS_LIMITED(301, "访问受限"),
    ARGS_ERROR(501, "参数错误"),
    UNKNOWN_ERROR(502, "系统异常"),
    INSERT_ERROR(503, "新增错误"),
    UPDATE_ERROR(504, "更新错误"),
    DELETE_ERROR(506, "删除错误"),
    UPLOAD_ERROR(507, "上传错误"),
    DOWNLOAD_ERROR(508, "下载错误"),
    OTHER_SYSTEM_ERROR(509, "调用系统异常");

    private int state;
    private String stateInfo;

    StateEnum(int state, String stateInfo) {
        this.state = state;
        this.stateInfo = stateInfo;
    }

    /**
     * 根据 状态码获取对应的信息
     *
     * @param state
     * @return
     */
    public static StateEnum stateOf(int state) {
        for (StateEnum stateEnum : values()) {
            if (stateEnum.getState() == state) {
                return stateEnum;
            }
        }
        return null;
    }
}
